package org.molamil.acto.types {
	import org.molamil.acto.types.DefaultTypeResolver;	
	
	import flexunit.framework.TestCase;	
	
	/**
	 * @author Jorge Hernandez
	 */
	public class DefaultTypeResolverTest extends TestCase {
		
		
		// PROPERTIES
		
		private var instance:DefaultTypeResolver;
		
		
		// CONSTRUCTOR
		
		public function DefaultTypeResolverTest(methodName:String = null) {
			super(methodName);
		}
		
		
		// PUBLIC METHODS
		
		override public function setUp():void {
			instance = new DefaultTypeResolver();
		}
		
		override public function tearDown():void {
			instance = null;
		}
		
		public function testParse():void {
			
			assertTrue("'true' parses to true", instance.parse("true") === true);
			assertTrue("'TRUE' parses to true", instance.parse("TRUE"));
			assertFalse("'FalsE' parses to false", instance.parse("FalsE"));
			
			assertTrue("'1' parses to 1", instance.parse("1") === 1);
			assertTrue("'0' parses to 0", instance.parse("0") === 0);
			assertEquals("'100' parses to 100", 100, instance.parse("100"));
			assertEquals("'32000000000000000000' parses to 32000000000000000000", 
				32000000000000000000, instance.parse("32000000000000000000"));
			assertEquals("'.5' parses to 0.5", 0.5, instance.parse(".5"));
			assertEquals("'0x100' parses to 256", 256, instance.parse("0x100"));
			assertEquals("'-0x100' parses to -256", -256, instance.parse("-0x100"));
			assertEquals("' Infinity' parses to Infinity", Infinity, instance.parse("Infinity"));
			assertEquals("'126e3' parses to 126000", 126000, instance.parse("126e3"));
			
			assertTrue("null parses to null", instance.parse(null) === null);
			
			assertEquals("'1979-10-21' parses to a date", new Date(1979, 9, 21).getTime(), 
				(instance.parse("1979-10-21") as Date).getTime());
			assertEquals("'Sun Oct 21 09:00:00 GMT+0200 1979' parses to a date", 
				new Date(1979, 9, 21, 9, 0, 0).getDate(), 
				(instance.parse("Sun Oct 21 09:00:00 GMT+0200 1979") as Date).getDate());
			assertEquals("'2008/07/23' parses to a date", new Date(2008, 6, 23).getTime(), 
				(instance.parse("2008/07/23") as Date).getTime());
				
			assertEquals("'0x5.5' parses to '0x5.5'", "0x5.5", instance.parse("0x5.5"));
			assertEquals("'' parses to ''", "", instance.parse(""));
			
		}
		
		
	}
	
}
